package pers.xhh.frontapi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.xhh.frontapi.annotation.UserLoginToken;
import pers.xhh.frontapi.common.Mi;
import pers.xhh.frontapi.entity.to.order.OrderSubmitTo;
import pers.xhh.frontapi.service.MiOrderService;

/**
 * @author wei-xhh
 * @date 2020-12-09
 */
@CrossOrigin
@RestController
@RequestMapping("/mi/api")
public class MiOrderController {

    @Autowired
    MiOrderService miOrderService;

    @UserLoginToken
    @GetMapping("/order")
    public Mi order(){
        return miOrderService.orderInfo();
    }

    @UserLoginToken
    @PostMapping("/order/confirm")
    public Mi confirmOrder(@RequestBody OrderSubmitTo orderSubmitTo){
        return miOrderService.confirmOrder(orderSubmitTo);
    }

    @UserLoginToken
    @GetMapping("/order/my")
    public Mi myOrder(@RequestParam(required = false) Integer pagenum,
                      @RequestParam(required = false) Integer pagesize){
        return miOrderService.myOrder(pagenum, pagesize);
    }

    @UserLoginToken
    @DeleteMapping("/order/{orderId}")
    public Mi cancelOrder(@PathVariable("orderId") Integer orderId){
        return miOrderService.cancelOrder(orderId);
    }

}
